package hongcaosp.app.android.redpacket;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import hongcaosp.app.android.R;
import xlj.lib.android.base.toastcompat.ToastManager;

public class RedPacketDialog extends Dialog {

    private ImageView moneyIV;
    private ImageView moneyTV;

    private ContentLoadingProgressBar progressBar;

    public RedPacketDialog(@NonNull Context context) {
        super(context,R.style.MoneyDialog);
    }

    public RedPacketDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected RedPacketDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setGravity(Gravity.CENTER);
        getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);

        setContentView(R.layout.dialog_redpacket);
        setCanceledOnTouchOutside(false);

        moneyIV = findViewById(R.id.money_icon);
        moneyTV = findViewById(R.id.money_tv);

        progressBar = findViewById(R.id.progressBar);

        moneyTV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(),RedPacketService.class);
                intent.putExtra("msgType",RedPacketService.MSGTYPE_CATCH_PACKET);
                getContext().startService(intent);
            }
        });
    }

    public void showProgress() {
        progressBar.setVisibility(View.VISIBLE);
        moneyTV.setVisibility(View.GONE);
    }

    public void showError(String error) {
        ToastManager.getInstance().showToast(error);
        moneyTV.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.INVISIBLE);
    }
}
